<template>
	<div class="container-wrap">
		<uni-nav-bar fixed shadow :border="false" :title="title" left-icon="left" @clickLeft="onClickLeft" v-if="title">
			<template #bottom>
				<div class="uni-nav-bottom">
					<uni-search-bar @confirm="searchList" v-model="name" placeholder="请输入搜索关键词" @clear="() => {
					name='';
					searchList()
				}" @cancel="searchList" cancelButton="none" :radius="20"></uni-search-bar>
				</div>
			</template>
		</uni-nav-bar>
		<div class="top-wrap active" v-else>
			<uni-search-bar @confirm="searchList" v-model="name" placeholder="请输入搜索关键词" @clear="() => {
				name='';
				searchList()
			}" @cancel="searchList" cancelButton="none" :radius="20"></uni-search-bar>
		</div>
		<div class="list-wrap common-wrap">
			<van-list v-model="listLoading" :finished="listFinished" finished-text="没有更多了" @load="loadMore">
				<ListItem :list="list" vertical></ListItem>
			</van-list>
		</div>
	</div>
</template>

<script>
	import ListItem from '@/components/questionnaire/listItem.vue'
	import VanList from "@/components/vant/van-list/van-list.vue";
	import mockData from "@/mock/index/configData.json"
	export default {
		data() {
			return {
				name: '', // 1
				page: {
					pageNumber: 1,
					pageSize: 10,
				},
				list: [], // 课程列表
				listLoading: false,
				listFinished: false,
			}
		},
		props: {
			title: {
				type: String,
				default: ''
			},
			isAllowAnonymous: {
				type: String,
				default: ''
			}
		},
		computed: {},
		components: {
			VanList,
			ListItem
		},
		mounted() {
			this.getList()
		},
		methods: {
			onClickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			searchList() {
				this.$toast.warning("搜索功能需自己实现")
			},
			getList() {
				let res = mockData.questionData;
				this.list = res;
				this.listFinished = true
				this.listLoading = false
			},
			loadMore() {
				if (!this.listFinished) this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.van-nav-bar.van-hairline--bottom::after {
		display: none;
	}

	:deep(.qy-com-learn-course) {
		padding-top: 50px;

		.search-bar {
			padding: 0;
		}

		.van-search {
			padding-top: 0;
		}

		.font-btn {
			margin-top: 8px !important;
		}
	}

	.container-wrap {
		position: relative;
	}

	.top-wrap {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 100;
		background: #fff;

		.van-nav-bar {
			&+.van-search {
				padding-top: 0;
			}
		}

		&.active {
			position: absolute;
			padding: 5px 0;

			&+.list-wrap {
				padding-top: 50px;
				height: calc(100vh - 235px);
			}
		}
	}

	.list-wrap {
		padding-top: 66px;
		overflow: auto;
		height: calc(100vh - var(--status-bar-height) - 56px);
	}
</style>